﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using YGLAB_SON.Models;

namespace YGLAB_SON.Controllers
{
    public class JournalController : Controller
    {
        private YgContext db = new YgContext();

        //
        // GET: /Journal/

        public ActionResult Index()
        {
            return View(db.Journals.ToList());
        }

        //
        // GET: /Journal/Details/5

        public ActionResult Details(int id = 0)
        {
            Journal journal = db.Journals.Find(id);
            if (journal == null)
            {
                return HttpNotFound();
            }
            return View(journal);
        }

        //
        // GET: /Journal/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Journal/Create

        [HttpPost]
        public ActionResult Create(Journal journal)
        {
            if (ModelState.IsValid)
            {
                db.Journals.Add(journal);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(journal);
        }

        //
        // GET: /Journal/Edit/5

        public ActionResult Edit(int id = 0)
        {
            Journal journal = db.Journals.Find(id);
            if (journal == null)
            {
                return HttpNotFound();
            }
            return View(journal);
        }

        //
        // POST: /Journal/Edit/5

        [HttpPost]
        public ActionResult Edit(Journal journal)
        {
            if (ModelState.IsValid)
            {
                db.Entry(journal).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(journal);
        }

        //
        // GET: /Journal/Delete/5

        public ActionResult Delete(int id = 0)
        {
            Journal journal = db.Journals.Find(id);
            if (journal == null)
            {
                return HttpNotFound();
            }
            return View(journal);
        }

        //
        // POST: /Journal/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            Journal journal = db.Journals.Find(id);
            db.Journals.Remove(journal);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}